package com.wlj.rabbit.api;

import com.wlj.rabbit.entity.Message;
import com.wlj.rabbit.produce.MessageSender;
import com.wlj.rabbit.util.ResultCodeEumn;
import com.wlj.rabbit.util.ResultEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @ClassName SendApi
 * @Description 消息生产方
 * @Author wlj
 * @Date 2018/11/15  11:22
 * @Version 1.0
 */
@RestController
public class SendApi {
    @Resource
    private MessageSender messageSender;


    @GetMapping(value="api/send/{key}/{text}")
    public ResultEntity sendMsg(@PathVariable String key,@PathVariable String text){
        try {
                return messageSender.send("message-exchange",key,new Message(System.currentTimeMillis()+"$"+UUID.randomUUID().toString(),text));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new ResultEntity(false,ResultCodeEumn.FAIELD);
    }
}
